package com.diorsunion.hedge.io;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by wangnima on 2016/5/29.
 */
public  interface MessageBO <T extends MessageHandler> {

    Map<String,List<T>> getMessageHandlerMap();

    default void initHandler(T messageHandler){
        if(messageHandler ==null){
            return;
        }
        Map<String,List<T>> map = getMessageHandlerMap();
        Set<Class> classSet= messageHandler.handlerClasses();
        for(Class clazz:classSet ){
            String className = clazz.getName();
            List<T> messageHandlerList = map.get(className);
            if(messageHandlerList ==null){
                messageHandlerList = Lists.newArrayList();
            }
            messageHandlerList.add(messageHandler);
            map.put(className, messageHandlerList);
        }
    }

    List<Message> execute(Message message);
}
